-
Notifications
You must be signed in to change notification settings - Fork 36
use int compare when both version fields are ints #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
src/Package.vala
Outdated
| } else if (a_num > b_num) { | ||
| return 1; | ||
| } | ||
| return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the strings "32.17.3" and "32.17.10" the method will return 0 and this is the culprit. Remove it and add a if(i == length-1) like in the original code
src/Package.vala
Outdated
| string[] aparts = aver.split ("."); | ||
| string[] bparts = bver.split ("."); | ||
|
|
||
| int length = int.max (aparts.length, bparts.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a problem coincidentally because you have return 0, but if you do it correctly it will cause out of array error, replace it with int.min and do the length comparison as above
src/Package.vala
Outdated
| bool b_is_num = int.try_parse(bparts[i], out b_num); | ||
|
|
||
| if (a_is_num && b_is_num) { | ||
| if (a_num < b_num) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(a_num != b_num)
return a_num - b_num;
is also faster for cpu than comparisons
|
We should diligently adhere to the version comparison specification, as described on the Debian site, see https://www.debian.org/doc/debian-policy/ch-controlfields.html#version. It's not only about the upstream version split by |
camilajenny
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will create a pr to your code when I'm ready
src/Package.vala
Outdated
| } | ||
| return 0; | ||
| } else { | ||
| return strcmp (aparts[i], bparts[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this changes the contract as strcmp doesn't have to return either -1, or 1 but any negative or positive number (cmp. below)
src/Package.vala
Outdated
|
|
||
| int rc = compare_versions (package.get_version (), version); | ||
| int rc = compare_versions (package.get_version (), version); | ||
| if (rc == 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
adhere to Debian version comparison guidelines
|
Update to support different debian version schemes, with tests! Thanks camilajenny! |
|
@donadigo Are you able to review this PR? Are you still supporting eddy? Thanks |
Fixes #129
Previous and after my change

